<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogVisible">
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="招聘等级" :label-width="formLabelWidth" prop="level">
          <el-input v-model="form.level" autocomplete="off" />
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="定金" :label-width="formLabelWidth" prop="deposit">
          <el-input v-model="form.deposit" autocomplete="off" />
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="首付款" :label-width="formLabelWidth" prop="down_payment">
          <el-input v-model="form.down_payment" autocomplete="off" />
        </el-form-item>
      </el-form>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item label="尾款" :label-width="formLabelWidth" prop="final_payment">
          <el-input v-model="form.final_payment" autocomplete="off" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitFun('form')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { uploadRecruitLevelApi } from '@/api/main'

export default {
  data() {
    return {
      title: '新增',
      dialogVisible: false,
      form: {
        level: '',
        deposit: '',
        down_payment: '',
        final_payment: ''
      },
      department_id: '',
      rules: {
        level: [
          { required: true, message: '请输入部门名称', trigger: 'blur' }
        ],
        deposit: [
          { required: true, message: '请输入定金', trigger: 'blur' }
        ],
        down_payment: [
          { required: true, message: '请输入首付款', trigger: 'blur' }
        ],
        final_payment: [
          { required: true, message: '请输入尾款', trigger: 'blur' }
        ]
      },
      formLabelWidth: '120px'
    }
  },
  methods: {
    submitFun(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          const data = this.form
          console.log(data)
          uploadRecruitLevelApi(data).then(res => {
            if (res.code === 200) {
              this.$message.success(res.msg)
              this.dialogVisible = false
              this.$emit('reloadFun')
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
